package com.ruoyi.broker.controller;

import com.ruoyi.broker.domain.Broker;
import com.ruoyi.broker.service.IBrokerService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 经纪人数据Controller
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/broker/broker")
public class BrokerController extends BaseController {
    @Autowired
    private IBrokerService brokerService;

    /**
     * 查询经纪人数据列表
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:list')")
    @GetMapping("/list")
    public TableDataInfo list(Broker broker) {
        startPage();
        List<Broker> list = brokerService.selectBrokerList(broker);
        return getDataTable(list);
    }

    /**
     * 导出经纪人数据列表
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:export')")
    @Log(title = "经纪人数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Broker broker) {
        List<Broker> list = brokerService.selectBrokerList(broker);
        ExcelUtil<Broker> util = new ExcelUtil<Broker>(Broker.class);
        util.exportExcel(response, list, "经纪人数据数据");
    }

    /**
     * 获取经纪人数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(brokerService.selectBrokerById(id));
    }

    /**
     * 新增经纪人数据
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:add')")
    @Log(title = "经纪人数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Broker broker) {
        return toAjax(brokerService.insertBroker(broker));
    }

    /**
     * 修改经纪人数据
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:edit')")
    @Log(title = "经纪人数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Broker broker) {
        return toAjax(brokerService.updateBroker(broker));
    }

    /**
     * 删除经纪人数据
     */
    @PreAuthorize("@ss.hasPermi('broker:broker:remove')")
    @Log(title = "经纪人数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(brokerService.deleteBrokerByIds(ids));
    }
}
